﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCDiaChi.ascx.cs" Inherits="Viewer.ToChuc.UserControls.UCDiaChi" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<link href="../../resources/css/main.css" rel="stylesheet" type="text/css" />
<ext:XScript ID="XScipt1" runat="server">
    <script type="text/javascript">
        {
         function ValidateDiaChi()
        {       
            if(CheckDataDiaChi()==true)
            { 
            }
            else
            {
              Ext.MessageBox.alert('Lỗi', 'Bạn chưa nhập đủ các trường cần thiết!');
                                    #{txtSoNha}.focus();
                                    return false;
            }
        }
        function CheckDataDiaChi()
        {
       
            if(#{txtSoNha}.getValue()=='')
            {
                return false;
            }
           
             if(#{cbbTinh}.getValue()=='')
            {
                return false;
            }
             if(#{cbbQuan}.getValue()=='')
            {
                return false;
            }
            
              if(#{txtGhiChu}.getValue()=='')
            {
                return false;
            }
            return true;
        }
        }
    </script>
</ext:XScript>
<ext:Window ID="wdDiaChi" runat="server" Width="450" AutoHeight="true" Modal="true"
    Closable="false" Hidden="true" HideBorders="True" Border="false" Plain="true"
    Resizable="false" Frame="false" Title="Tạo mới địa chỉ" Icon="BookAddresses">
    <Items>
        <ext:Panel ID="Panel1" runat="server" Frame="true" Height="200" BodyStyle="background-color:white;">
            <Content>
                <table>
                    <tr style="display: none;">
                        <td>
                            <ext:Hidden runat="server" ID="hdStatus">
                            </ext:Hidden>
                            <ext:TextField ID="txtId" runat="server" ReadOnly="true" Width="50" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Số nhà
                        </td>
                        <td>
                            <ext:TextField ID="txtSoNha" runat="server" Width="300" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Tỉnh Thành
                        </td>
                        <td>
                            <ext:ComboBox ID="cbbTinh" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                                EmptyText="Chọn Tỉnh/Thành Phố">
                                <Store>
                                    <ext:Store ID="storeTinh" runat="server">
                                        <Reader>
                                            <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                                <Fields>
                                                    <ext:RecordField Name="TenToChucHanhChinh" />
                                                    <ext:RecordField Name="ToChucHanhChinhID" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                    </ext:Store>
                                </Store>
                                <Triggers>
                                    <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                </Triggers>
                                <Listeners>
                                    <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Quan');this.triggers[0].show();" />
                                    <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                    <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                </Listeners>
                            </ext:ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Quận Huyện
                        </td>
                        <td>
                            <ext:ComboBox ID="cbbQuan" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                                EmptyText="Chọn Quận/Huyện">
                                <Store>
                                    <ext:Store ID="storeQuan" runat="server">
                                        <Reader>
                                            <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                                <Fields>
                                                    <ext:RecordField Name="TenToChucHanhChinh" />
                                                    <ext:RecordField Name="ToChucHanhChinhID" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                    </ext:Store>
                                </Store>
                                <Triggers>
                                    <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                </Triggers>
                                <Listeners>
                                    <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Xa');this.triggers[0].show();" />
                                    <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                    <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                </Listeners>
                            </ext:ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Xã phường
                        </td>
                        <td>
                            <ext:ComboBox ID="cbbXa" runat="server" DisplayField="TenToChucHanhChinh" ValueField="ToChucHanhChinhID"
                                EmptyText="Chọn Quận/Huyện">
                                <Listeners>
                                    <Select Handler="#{DirectMethods}.LoadQuan(record.id,'Thon');" />
                                </Listeners>
                                <Store>
                                    <ext:Store ID="storeXa" runat="server">
                                        <Reader>
                                            <ext:JsonReader IDProperty="ToChucHanhChinhID">
                                                <Fields>
                                                    <ext:RecordField Name="TenToChucHanhChinh" />
                                                    <ext:RecordField Name="ToChucHanhChinhID" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                    </ext:Store>
                                </Store>
                                <Triggers>
                                    <ext:FieldTrigger Icon="Clear" HideTrigger="true" />
                                </Triggers>
                                <Listeners>
                                    <Select Handler="this.triggers[0].show();" />
                                    <BeforeQuery Handler="this.triggers[0][ this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                    <TriggerClick Handler="if (index == 0) { this.clearValue(); this.triggers[0].hide(); }" />
                                </Listeners>
                            </ext:ComboBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Thôn phố
                        </td>
                        <td>
                            <ext:TextField ID="txtThonPho" runat="server" Width="200" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Ghi chú
                        </td>
                        <td>
                            <ext:TextField ID="txtGhiChu" runat="server" Width="300" />
                        </td>
                    </tr>
                </table>
            </Content>
            <Buttons>
                <ext:Button ID="btnSave" runat="server" Text="Lưu" Icon="Disk">
                    <Listeners>
                        <Click Handler=" Ext.net.Mask.show();" />
                    </Listeners>
                    <DirectEvents>
                        <Click OnEvent="btnSave_Click">
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="Button1" runat="server" Text="Đóng" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{wdDiaChi}.hide();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:Panel>
    </Items>
</ext:Window>
